﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Guline.SupportCMS.Models.Object;
using Guline.SupportCMS.Models.Context;

namespace Guline.SupportCMS.Controllers.Manage
{
    public class VideoCategoryController : GulineBaseController
    {
     
        //
        // GET: /VideoCategory/

        public ActionResult Index()
        {
            var videocategorys = db.VideoCategorys.Include(v => v.Category).Include(v => v.Video);
            return View(videocategorys.ToList());
        }

        //
        // GET: /VideoCategory/Details/5

        public ActionResult Details(int id = 0)
        {
            VideoCategory videocategory = db.VideoCategorys.Find(id);
            if (videocategory == null)
            {
                return HttpNotFound();
            }
            return View(videocategory);
        }

        //
        // GET: /VideoCategory/Create

        public ActionResult Create()
        {
            ViewBag.CategoryID = new SelectList(db.Categories, "ID", "Name");
            ViewBag.VideoID = new SelectList(db.Videos, "ID", "Name");
            return View();
        }

        //
        // POST: /VideoCategory/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(VideoCategory videocategory)
        {
            if (ModelState.IsValid)
            {
                db.VideoCategorys.Add(videocategory);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.CategoryID = new SelectList(db.Categories, "ID", "Name", videocategory.CategoryID);
            ViewBag.VideoID = new SelectList(db.Videos, "ID", "Name", videocategory.VideoID);
            return View(videocategory);
        }

        //
        // GET: /VideoCategory/Edit/5

        public ActionResult Edit(int id = 0)
        {
            VideoCategory videocategory = db.VideoCategorys.Find(id);
            if (videocategory == null)
            {
                return HttpNotFound();
            }
            ViewBag.CategoryID = new SelectList(db.Categories, "ID", "Name", videocategory.CategoryID);
            ViewBag.VideoID = new SelectList(db.Videos, "ID", "Name", videocategory.VideoID);
            return View(videocategory);
        }

        //
        // POST: /VideoCategory/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(VideoCategory videocategory)
        {
            if (ModelState.IsValid)
            {
                db.Entry(videocategory).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.CategoryID = new SelectList(db.Categories, "ID", "Name", videocategory.CategoryID);
            ViewBag.VideoID = new SelectList(db.Videos, "ID", "Name", videocategory.VideoID);
            return View(videocategory);
        }

        //
        // GET: /VideoCategory/Delete/5

        public ActionResult Delete(int id = 0)
        {
            VideoCategory videocategory = db.VideoCategorys.Find(id);
            if (videocategory == null)
            {
                return HttpNotFound();
            }
            return View(videocategory);
        }

        //
        // POST: /VideoCategory/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            VideoCategory videocategory = db.VideoCategorys.Find(id);
            db.VideoCategorys.Remove(videocategory);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}